package org.tvolkov.mycompany



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Company)
class CompanyTests {

	@Before
	void setUp(){
		def cmp1 = new Company(name: "name");
		mockForConstraintsTests(Company, [cmp1]);
	}
	
    void testNameBlank(){
		def cmp = new Company(name: "");
		assertFalse cmp.validate();
		assertEquals "blank", cmp.errors["name"];
		
		cmp = new Company(name: "not blank", address: "", phoneNumber: "");
		assertTrue cmp.validate();
		assertNull "blank", cmp.errors["name"];	
	}
	
	void testNameUnique(){
		def cmp = new Company(name: "name");
		assertFalse cmp.validate();
		assertEquals "unique", cmp.errors["name"];
		
		cmp = new Company(name: "name123", address: "", phoneNumber: "");
		assertTrue cmp.validate();
		assertNull "unique", cmp.errors["name"];
	}
	
	void testBlank(){
		def cmp = new Company(name: "name1", address: "", phoneNumber: "");
		assertTrue cmp.validate();
		assertNull cmp.errors["address"];
		assertNull cmp.errors["phoneNumber"];
	}
	
	void testNullable(){
		def cmp = new Company(name: "company");
		assertTrue cmp.validate();
		assertNull cmp.errors["address"];
		assertNull cmp.errors["phoneNumber"];
	}
	
}
